const prefix = this.pageObj.getVariables().find(v => v.name === 'environmentType')?.value || '';
console.log('$event-------->', $event);
const playBack = this.getApiPage().getApiWidgetByAliasName('录像回放')?.widgetObj;
var authTokenVar = this.getApiPage().getVariables().find(x => x.name == "AuthToken");
function baseGet(url) {
    const headers = { "Content-type": "application/json" }
    return fetch(url, { headers }).then(res => res.json())
}

if ($event.type === 'DETAIL') {
    let eventData;
    try {
        eventData = JSON.parse($event.data)
    } catch (e) {
        console.error(e)
    }

    if ($event.typeName === '接警') {
        baseGet(`/${prefix}Event/event/receivingAlarm/${eventData.id}`)
    }
    console.log('-------->', $event)
    window.parent.postMessage({ type: 'nav/style', pageName: '事件' }, document.referrer);


    this.getApiPage().navigateStage('829716080812359680', [{ name: 'screen_params', value: $event.data },
        { name: 'AuthToken', value: (authTokenVar ? authTokenVar.value : '') }])
} else if ($event.type === 'sxjhf') {
    // 回放
    if ($event.data.equipmentConfig) {
        playBack.addRecorderEquipment({ equipmentConfig: $event.data.equipmentConfig });
    } else {
        window.layer?.msg('未找到录像机配置！');
    }
} else if ($event.type === 'DISPOSE') {
    window.parent.postMessage({ type: 'nav/style', pageName: '处置' }, document.referrer);
    let __data = $event.data;

    if (typeof __data !== 'string') {
        __data = JSON.stringify($event.data)
    }
    this.getApiPage().navigateStage('833630884086153216', [
        { name: 'screen_params', value:  __data },
        { name: 'AuthToken', value: authTokenVar },
        { name: 'environmentType', value: prefix },
        { name: 'isOther', value: '1' },
    ])
}
